package com.system.demo.controller.auth;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.system.demo.entity.auth.DTO.AddRoleDTO;
import com.system.demo.entity.auth.DTO.MenuIdsDTO;
import com.system.demo.service.auth.SystemRoleService;
import com.system.demo.tool.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/role")
public class SystemRoleController {

    @Autowired
    private SystemRoleService systemRoleService;


    //查询最新的系统角色表
    @GetMapping
    @SaCheckPermission(value = {"PermAssignment","MemberManagement"},mode = SaMode.OR)
    public ResponseResult<?> getTheNewestRoleTable(){
        return systemRoleService.getTheNewestRoleTable();
    }


    //增加角色 要求角色的基本定义 以及 角色对应的的menu有哪些 先想想DTO有哪些
    @PostMapping("/addRole")
    @SaCheckPermission("PermAssignment")
    public ResponseResult<?> addRole(@RequestBody AddRoleDTO addRoleDTO) {
        return systemRoleService.addRole(addRoleDTO);
    }
    //删除角色 要删除user_role 中所有role_id的记录  以及 system_role里面的记录 还要有 role_menu的对应记录
    //最快的办法就是直接把is_available设置成0 就行了
    @DeleteMapping
    @SaCheckPermission("PermAssignment")
    public ResponseResult<?> deleteRole(@RequestParam Integer roleId){
        return systemRoleService.deleteRole(roleId);
    }

    //启用角色
    @GetMapping("/enableRole")
    @SaCheckPermission("PermAssignment")
    public ResponseResult<?> enableRole(@RequestParam Integer roleId){
        return systemRoleService.enableRole(roleId);
    }

    //更改角色权限  可以理解成 更改后的menuList - 更改前的menuList ，往这个角色添加这两者的差值 DTO
    @PutMapping
    @SaCheckPermission("PermAssignment")
    public ResponseResult<?> updateRoleMenuList(@RequestParam Integer roleId, @RequestBody MenuIdsDTO menuIds){
        return systemRoleService.updateRoleMenuList(roleId, menuIds);
    }

    //根据roleId返回menuId List
    @GetMapping("/getMenus")
    @SaCheckPermission("PermAssignment")
    public ResponseResult<?> getMenuIdsForRole(@RequestParam Integer roleId){
        return systemRoleService.getMenuIdsForRole(roleId);
    }

    //查看当前系统的Menu结构
    @GetMapping("/getMenuList")
    @SaCheckPermission("PermAssignment")
    public ResponseResult<?> getUserMenuList(){
        return systemRoleService.getUserMenuList();
    }

    //查看当前系统的副管理员 有哪些
}
